<?php

	header("Content-Type: text/html;charset=utf-8");

	include("function/_nosql.php"); //

	include("function/function.php");

	

	$action = chkstr(trim($_REQUEST['action']));

	$user_email = chkstr(trim($_REQUEST['user_email']));

	$user_password = chkstr(trim($_REQUEST['user_password']));

	$user_passcode = chkstr(trim($_REQUEST['user_passcode']));

	$redirect_urls = chkstr(trim($_REQUEST['redirect_urls']));
	
	if($action == "chklogin"){
		// 验证Email 手机号

		if(strlen($user_email)<1){
			echo erro("Email或手机号不能为空");

		}

//		if(!isEmail($user_email) && !isMobile($user_email) ){
//
//			echo erro("Email或手机号格式错误");
//
//		}

		// 验证密码

		if(strlen($user_password)<1){

			echo erro("密码不能为空");

		}

		// 验证验证码

		if(strlen($user_passcode)<1){

			echo erro("验证码不能为空");

		}

		if(isNumber($user_passcode) == false){

			echo erro("验证码只能为数字");

		}

		if($user_passcode != $_SESSION['verifyCode']){

			echo erro("验证码错误");

		}

		

		

		// MD5双层加密
        
		$user_password = md5(md5($user_password));

		$is_reguser = getNewsNums("kboy_user"," ( user_email='$user_email' or user_phone='$user_email' )  AND user_password='$user_password'");
		if($is_reguser >0){

			$_SESSION['kboy_user'] = $user_email;

			$_SESSION['kboy_userid'] = getClassName("kboy_user","uid","( user_email='$user_email' or user_phone='$user_email' )");

			$_SESSION['kboy_leader'] = getClassName("kboy_user","user_leader","( user_email='$user_email' or user_phone='$user_email' )");
			$zi = isset($_REQUEST['zidong']) ?$_POST['zidong'] : null;
				if(!is_null($zi)){
						setcookie("username",$user_email,time()+3600*24*365);
   						setcookie("password",$user_password,time()+3600*24*365);
				}
			if($redirect_urls){

				mysql_query("update kboy_user set user_lasttime='$THIS_TODAY_DATETIME',user_lastip='".getip()."' where ( user_email='$user_email' or user_phone='$user_email' )");
				
				echo re(urldecode($redirect_urls));
				

//				if(substr_count($redirect_urls,'login.php')>0 || substr_count($redirect_urls,'reg.php')>0){
//
//					echo re("user_index.php");
//
//				}else{
//
//					echo re("user_index.php");
//
//					//echo re(urldecode($redirect_urls));
//
//				}

				//echo re("user_index.php");

			}else{

				echo re("user_index.php");

			}

		}else{

			echo erro("Email/手机号或密码错误");

		}

	}else{

		echo erro("参数错误");

	}

?>